import React, { Component } from 'react';
import pic from '../../assets/3.png'
import '../../styles/Mheader.css'
import { withRouter } from 'react-router-dom';
import {getFavlist} from '../../api/collect'
class Head extends Component {
    constructor(props){
        super(props)
        this.state={
            num:1
        }
    }
    async componentDidMount(){
        let res=await getFavlist({userid:localStorage.getItem('id')})
               // console.log(res.data.list,"收藏列表");
               this.setState({
                 num:res.data.list.length
               })       
       }
    goCollect(){
        this.props.history.push('/collect')
    }
    render() {
        return (
            <div className='head'>
                <div className='bg'>
                    <div className='imgbox'>
                        <img src={pic} alt="" />
                    </div>
                    <span>啦啦啦</span>
                </div>
                <div className='msg'>
                    <p onClick={()=>{this.goCollect()}}>
                        <span>{this.state.num}</span>
                        <span>收藏</span>
                    </p>
                    <p>
                        <span>0</span>
                        <span>积分</span>
                    </p>
                    <p>
                        <span>0</span>
                        <span>优惠券</span>
                    </p>
                </div>
            </div>

        );
    }
}

export default withRouter(Head);